<div class="span12">
    <div class="common">
        <div class="whiteBg blueBor padding20px">
            <h5 class="fnt-size20">Create A Class</h5>
        </div>
    </div>
    <div class="common"> <fieldset>
            <div class="createBox addmarginB20">
                <h4 class="txtfff fnt-size20"><span class="stepCount">Step 3</span>Class Photo</h4>
                <div id="errortext" style="width: 95%;margin: 0 auto;color: red"></div>
                <p class="alignL fnt-size14 padding10px"><?php echo Message::CLASS_PHOTO ?></p>
                <?php
                $form = $this->beginWidget('GxActiveForm', array(
                    'id' => 'classes-form',
                    'htmlOptions' => array('enctype' => 'multipart/form-data'),
                        ));


                $this->widget('xupload.XUpload', array(
                    'url' => Yii::app()->createUrl("classImage/upload"),
                    'model' => $photos,
                    'htmlOptions' => array('id' => 'classes-form'),
                    'attribute' => 'file',
                    'multiple' => true,
                    'showForm' => false,
                    'options' => array(
                        'maxNumberOfFiles' => SkillConfig::MAX_FILE_UPLOAD_LIMIT,
                        'maxFileSize' => SkillConfig::MAX_IMAGE_SIZE_UPLOAD,
                    ),
                        )
                );
                ?>

            </div></fieldset>
    </div>

    <div class="common">
        <p class="alignR"> <input type="button" class="btn twoBtn" value="Back" id="<?php echo $authKey; ?>" onclick="setAuthKey(this.id, 'ClassVenue/Classvenue')">
            <?php echo GxHtml::submitButton(Yii::t('app', 'Save & Continue'), array('class' => 'btn', 'id' => 'saveClassImage')); ?></p>
    </div>
    <?php $this->endWidget(); ?>

    <?php
    if (isset($authKey)) {
        $classes = Classes::model()->findByAttributes(array('auth_key' => $authKey));
        $classWithImage = Classes::getclassWithImage($classes->id);
        $dataProvider = new CArrayDataProvider($classWithImage, array(
                    'id' => 'classimage',
                    'sort' => array(
                        'attributes' => array(
                            'id', 'photo', 'class_id',),
                    ),
                    'pagination' => array(
                        'pageSize' => 10,),));


        $this->widget('zii.widgets.grid.CGridView', array(
            'id' => 'classimage-grid',
            'dataProvider' => $dataProvider,
            'columns' => array(
                array(
                    'name' => 'Image',
                    'type' => 'image',
                    'value' => 'Classes::classImageingridView($data)',
                    'htmlOptions' => array('style' => 'text-align: center'),
                ),
                array(
                    'name' => 'Primary image',
                    'value' => 'ClassImage::isPrimaryImage($data)',
                    'htmlOptions' => array('style' => 'text-align: center;padding:5px;'),
                ),
                array(
                    'id' => 'autoId',
                    'header' => 'Delete Image',
                    'class' => 'CCheckBoxColumn',
                    'selectableRows' => '50',
                    'checkBoxHtmlOptions' => array('name' => 'idList[]', 'onclick' => 'deleteAllRecord()', 'class' => 'deleteAllRecord'),
                ),
            ),
        ));
        $count = count($classWithImage) == '0' ? '' : count($classWithImage);
    }
    echo '<input type="hidden" name="imagevalidation" id="imagevalidation" value=>';
    echo '<input type="hidden" name="addimagevalidation" id="addimagevalidation" value=>';
    ?>

</div>
</div>
<script type="text/javascript">
    $(document).ready( function() {
 
        $("#confirm_box").click( function() {

        });
 
    });
</script>

<script type="text/javascript">
    function ChangeStatus(id, classid) {
        jConfirm('Are you sure want to make primary image?', 'Skillhippo  Confirmation', function(r) {
            if (r != false) {
                var ajaxloader = "<?php echo baseUrl() . "/images/" . '/ajax-loader.gif'; ?>";
                $("#imgadmin_" + id).attr("src", ajaxloader)
                $("#imgadmin_" + id).attr("onclick", "")
                jQuery.ajax({
                    'type': 'POST',
                    'url': "<?php echo Yii::app()->createUrl("classImage/primaryImage"); ?>",
                    'data': 'id=' + id + '&classid=' + classid,
                    'beforeSend': function(jqXHR, settings) {
                        $("#imgadmin_" + id).attr("src", ajaxloader)
                        $("#imgadmin_" + id).attr("onclick", "")
                    },
                    'success': function(json) {
                        var data = jQuery.parseJSON(json);
                        if (data.primary_image == '1') {
                            $("img[src$='active.png'][name='primary']").attr("src", "<?php echo baseUrl() . "/images/" . '/deactive.png' ?>");
                            var enableImg = "<?php echo baseUrl() . "/images/" . '/active.png' ?>";
                            $("#imgadmin_" + id).attr("src", enableImg);
                            $("#imgadmin_" + id).attr("onclick", "ChangeStatus(" + id + "," + data.classes_id + ")");
                        }
                    },
                    'cache': false
                })
            } 
        });
      
    }




    function getPrimaryImage(id) {
        jConfirm('Are you sure want to make primary image ?','Skillhippo  Confirmation', function(r) {
            if (r != false) {
                var imagename = id;
                $.post("<?php echo Yii::app()->createUrl("classImage/makePrimaryImage"); ?>", {imagename: imagename}, function(result) {
                });
            }
        });
    }


    function deleteAllRecord() {
        var idList = $(".deleteAllRecord:checked").serialize();
        if (idList) {
            jConfirm('Are you sure want to delete image ?', 'Skillhippo  Confirmation', function(result) {
                if (result != false) {
                    $.post("<?php echo Yii::app()->createUrl("classImage/deleteClassImage"); ?>", idList, function(response) {
                        location.reload('#classImage-id');
                    });
                }
            });
        }
    }
    $("#autoId_all").change(function() {
        $('.deleteAllRecord').attr('checked', 'checked');
        var idList = $(".deleteAllRecord:checked").serialize();
        if (idList) {
            jConfirm('Are you sure want to delete image ?', 'Skillhippo  Confirmation', function(r) {
                if (r != false) {
                    $.post("<?php echo Yii::app()->createUrl("classImage/deleteClassImage"); ?>", idList, function(response) {
                        location.reload('#classImage-id');
                    });
                }
            });
        }
        $('.deleteAllRecord').removeAttr('checked');
    })
    $('.multipleImage').click(function() {
        var k = $('#addimagevalidation').val();
        if (k == 1) {
            $('#imagevalidation').val('1')
        }
    })
    $('#XUploadForm_file').click(function() {
        $('#addimagevalidation').val('1')
    })
    $('.cancelImage').click(function() {
        $('#addimagevalidation').val('')
        $('#imagevalidation').val('')
    })
    $("#saveClassImage").click(function() {
        var image1 = $('#addimagevalidation').val();
        var image2 = $('#imagevalidation').val();
        if (image2 == '' || image1 == '')
        {
            $("#errortext").text('Please Upload image');
            return false;
        }

    });

</script>



